package com.zhangsun.springRabbitMq.producer;

import com.zhangsun.springRabbitMq.common.RabbitMqTopicConstant;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Topic模式生产者
 */
@Component
public class TopicProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送消息
     */
    public void sendTopic() {
        // 第一个参数：TopicExchange名字
        // 第二个参数：Route-Key
        // 第三个参数：要发送的内容
        rabbitTemplate.convertAndSend(RabbitMqTopicConstant.TOPIC_EXCHANGE_HELLO, "lzc.message", "world1");
        // rabbitTemplate.convertAndSend(RabbitMqTopicConstant.TOPIC_EXCHANGE_HELLO, "hello.message", "world2");
    }

}
